﻿namespace RefactoringMethods
{
    using System;

    internal class RefactoringMethodsMain
    {
        internal static double CalculateTriangleArea(double a, double b, double c)
        {
            if (a <= 0 || b <= 0 || c <= 0)
            {
                throw new ArgumentException("Error! Not valid triangle side");
            }

            double semiPerimeter = (a + b + c) / 2;
            double area = Math.Sqrt(semiPerimeter * (semiPerimeter - a) * (semiPerimeter - b) * (semiPerimeter - c));

            return area;
        }

        internal static string ConvertDigitFromFigureToText(byte number)
        {
            switch (number)
            {
                case 0: return "zero";
                case 1: return "one";
                case 2: return "two";
                case 3: return "three";
                case 4: return "four";
                case 5: return "five";
                case 6: return "six";
                case 7: return "seven";
                case 8: return "eight";
                case 9: return "nine";
                default: throw new ArgumentException("Error! Not a digit");
            }
        }

        internal static int FindMaxIntegerValue(params int[] elements)
        {
            if (elements == null || elements.Length == 0)
            {
                throw new ArgumentNullException("Error! Missing parameters");
            }

            int maxValue = int.MinValue;

            for (int i = 0; i < elements.Length; i++)
            {
                if (elements[i] > maxValue)
                {
                    maxValue =  elements[i];
                }
            }

            return maxValue;
        }

        internal static string FormatNumberWithTwoDigitsAfterTheDecimal(double number)
        {
            string numberAsString = String.Format("{0:f2}", number);

            return numberAsString;
        }

        internal static string ConvertNumberToPercentage(double number)
        {
            string numberAsPercentage = String.Format("{0:p0}", number);

            return numberAsPercentage;
        }

        internal static void PrintTextWithLeftAlignment(string text, int intervals)
        {
            string formatString = "\"{0," + intervals + "\"";

            Console.Write(formatString, text);
        }

        internal static bool IsHorizontalCheck(double yCoord1, double yCoord2)
        {
            bool isHorizontal = (yCoord1 == yCoord2);

            return isHorizontal;
        }

        internal static bool IsVerticalCheck(double xCoord1, double xCoord2)
        {
            bool isVertical = (xCoord1 == xCoord2);

            return isVertical;
        }

        internal static double CalculateDistance2D(double x1, double x2, double y1, double y2)
        {
            if (x1 == x2 && y1 == y2)
            {
                throw new ArgumentException("Error! Invalid line co-ordinates");
            }

            double distance = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));

            return distance;
        }

        private static void Main()
        {
            Console.WriteLine(CalculateTriangleArea(3, 4, 5));

            Console.WriteLine(ConvertDigitFromFigureToText(5));

            Console.WriteLine(FindMaxIntegerValue(5, -1, 3, 2, 14, 2, 3));


            Console.WriteLine(FormatNumberWithTwoDigitsAfterTheDecimal(1.3));
            Console.WriteLine(ConvertNumberToPercentage(7.5));

            PrintTextWithLeftAlignment((2.3).ToString(), 8);

            Console.WriteLine(CalculateDistance2D(3, -1, 3, 2.5));
            Console.WriteLine("Horizontal?" + IsHorizontalCheck(1.2, 1.2));
            Console.WriteLine("Vertical?" + IsVerticalCheck(2.3, 2.3));

            Student peter = new Student("Peter", "Ivanov", "17.03.1992");

            Student stella = new Student("Stella", "Markova", "03.11.1993");

            Console.WriteLine("{0} older than {1} -> {2}",
                peter.FirstName,
                stella.FirstName,
                peter.IsOlderThan(stella));
        }
    }
}